package com.qf.bootdaily.controller;

import com.qf.bootdaily.entity.User;
import com.qf.bootdaily.service.UserService;
import com.qf.bootdaily.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Objects;

@RestController
public class login {
    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Response<User> login(String username, String password, HttpSession session){
        User login = userService.login(username, password);
        if (Objects.nonNull(login)){
            session.setAttribute("user",login);
            return Response.success(login);
        }else {
            return Response.fail();
        }
    }
}
